/*
 * @Author: Wxx
 * @Date: 2022-02-25 15:41:19
 * @LastEditors: Wxx
 * @LastEditTime: 2022-02-26 19:34:46
 * @Description:
 */
import { combineReducers, createStore, applyMiddleware, compose } from "redux";
//引入redux-thunk是为了解决异步的action
import thunk from "redux-thunk";
import reduxPromise from "redux-promise";
import Tabbar from "./reducers/Tabbar";
import City from "./reducers/City";
import Cinemas from "./reducers/CinemasList";
// const reducers = (
//   prevState = {
//     show: false,
//     cityName: "成都",
//   },
//   action
// ) => {
//   const newState = { ...prevState };
//   switch (action.type) {
//     case "showTabbar":
//       newState.show = true;
//       return newState;
//     case "hideTabbar":
//       newState.show = false;
//       return newState;
//     case "cityChange":
//       newState.cityName = action.payload;
//       return newState;
//     default:
//       return prevState;
//   }
// };

//可以根据不同的业务拆分出多个reducer 方便多人同时开发 便于维护 在通过combineReducers进行合并
// 但是在拿state时需要store.getState().Tabbar.show这种去拿
const reducers = combineReducers({
  Tabbar,
  City,
  Cinemas,
});
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(
  reducers,
  composeEnhancers(applyMiddleware(thunk, reduxPromise))
);
export default store;
